import 'package:demo_proj01/repository/api_client.dart';
import 'package:demo_proj01/repository/datas/banner_data.dart';
import 'package:demo_proj01/repository/datas/home_list_data.dart';
import 'package:flutter/material.dart';

class HomeViewModel with ChangeNotifier {
  List<BannerItemData>? bannerList;
  List<HomeListItemData>? homeList;
  int pageIndex = 0;

  Future getBannerList() async {
    bannerList = await ApiClient.getBannerList();
    notifyListeners();
  }

  Future getHomeList(bool loadMore) async {
    if (loadMore) {
      ++pageIndex;
    } else {
      pageIndex = 0;
      homeList?.clear();
    }
    List<HomeListItemData>? listData = await ApiClient.getHomeList(pageIndex);
    if (homeList == null) {
      homeList = listData;
    } else {
      homeList?.addAll(listData);
    }
    notifyListeners();
  }
}
